<?php

$params = call_user_func_array(['yii\helpers\ArrayHelper', 'merge'], [
    require __DIR__ . '/../../../common/config/params.php',
    require __DIR__ . '/../../../common/config/params-local.php',
    require __DIR__ . '/params.php',
    require __DIR__ . '/params-local.php'
]);

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    'components' => [
        'request' => [
            'csrfParam' => '_csrf-frontend',
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ],
        ],
        'errorHandler' => [
            'class' => 'common\base\ErrorHandler',
            'custom' => false
        ],
//        'response' => [
//            'class' => 'yii\web\Response',
//            'format' => \yii\web\Response::FORMAT_JSON,
//            'on beforeSend' => function ($event) {
//                $sender = $event->sender;
//                if ($sender->statusCode == 200) {
//                    $responseData = [
//                        'code' => $sender->statusCode,
//                        'msg' => 'Success',
//                        'data' => $sender->data,
//                    ];
//                    $responseData['data'] = $sender->data;
//                } else {
//                    $responseData = $sender->data;
//                }
//                if (YII_DEBUG) {
//                    $request = Yii::$app->getRequest();
//                    $debug = [
//                        'url' => $request->getUrl(),
//                        'method' => $request->getMethod(),
//                        'queryParams' => $request->getQueryParams(),
//                        'bodyParams' => $request->getBodyParams(),
//                    ];
//                    $headers = $request->getHeaders()->toArray();
//                    foreach ($headers as $key => $vls) {
//                        $headers[$key] = $vls[0];
//                    }
//                    $debug['headers'] = $headers;
//                    $responseData['_debug'] = $debug;
//                }
//                $sender->data = $responseData;
//            },
//        ],
        'user' => [
            'identityClass' => 'frontend\models\User',
            'enableAutoLogin' => true,
            'enableSession' => false,
            'loginUrl' => null
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            //'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => require __DIR__ . '/restful.php',
        ],
    ],
    'modules' => require(__DIR__ . '/modules.php'),
    'params' => $params,
];
